package com.scnu.common.utils;

import com.scnu.common.domain.po.User;

public class UserContext {
    private static final ThreadLocal<User> threadLocal = new ThreadLocal<>();



    public static void setUser(User user) {
        threadLocal.set(user);
    }

    /**
     * 获取当前登录用户id
     * @return 用户id
     */
    public static Integer getUserId() {
        if (threadLocal.get() == null){
            return null;
        }
        return threadLocal.get().getId();
    }

    public static User getUser() {
        return threadLocal.get();
    }


    /**
     * 移除当前token信息
     */
    public static void remove(){
        threadLocal.remove();
    }
}
